package com.hds.modules.app.entity;

import com.baomidou.mybatisplus.annotations.TableField;
import com.baomidou.mybatisplus.annotations.TableId;
import com.baomidou.mybatisplus.annotations.TableName;
import com.hds.modules.app.utils.DateUtils;
import com.hds.modules.sys.entity.base.SysCompanyEntity;
import com.hds.modules.sys.entity.base.SysMemberShipEntity;

import java.io.Serializable;
import java.util.Date;

/**
 * @Author guonan
 * @Email guonan@yewcn.com
 * @Description 激活码实体类
 * @Date 2018/6/11 10:17
 */
@TableName("tb_activation_code")
public class ActivationCodeEntity implements Serializable, Comparable<ActivationCodeEntity>{
    private static final long serialVersionUID = 1L;


    public static final String LEVELPREFIX = "00";



    @Override
    public int compareTo(ActivationCodeEntity code) {
        Long d = days(code.getExpireTime()) - days(this.getExpireTime());// 先按照已激活的激活码有效期剩余天数排序
//        if(d == 0){
//            return this.** - code.get***;//如果天数相等了再用**进行排序
//        }
        return Integer.valueOf(String.valueOf(d));
    }

    // 查询当前已激活的激活码有效期剩余天数
    private Long days(Date expireTime){
        return DateUtils.timespaceOfDays(new Date(), expireTime);
    }


    @TableId
    private Integer id;

    // 激活码
    private String activationcode;

    // 激活码卡号
    private String cardNo;

    // 会员卡级别id  [如：1,注册会员，2-VIP会员卡,3-金卡]
    private Integer levelId;

    // 创建时间
    private Date createTime;

    // 激活码状态[ 0:enabled可用, 1:activated已激活, 2:expired已过期]
    private Integer status;

    // 激活时间
    private Date activateTime;

    // 用户id
    private Integer uid = null;

    // 公司id
    private Integer companyId;

    // 过期时间
    private Date expireTime;

    // 激活码服务年限[单位：年]
    private Integer period;

    //激活码保质期
    private Date guarantee;

    //批次【第几批生成的激活码】
    private Integer batch;

    //该激活码所在excel文件名
    private String excelFileName;

    @TableField(exist=false)
    private SysMemberShipEntity ship;
    @TableField(exist=false)
    private SysCompanyEntity Company;



    public SysMemberShipEntity getShip() {
        return ship;
    }

    public void setShip(SysMemberShipEntity ship) {
        this.ship = ship;
    }

    public SysCompanyEntity getCompany() {
        return Company;
    }

    public void setCompany(SysCompanyEntity company) {
        Company = company;
    }

    public Integer getId() {
        return id;
    }

    public void setId(Integer id) {
        this.id = id;
    }

    public String getActivationcode() {
        return activationcode;
    }

    public void setActivationcode(String activationcode) {
        this.activationcode = activationcode;
    }

    public String getCardNo() {
        return cardNo;
    }

    public void setCardNo(String cardNo) {
        this.cardNo = cardNo;
    }

    public Integer getLevelId() {
        return levelId;
    }

    public void setLevelId(Integer levelId) {
        this.levelId = levelId;
    }

    public Date getCreateTime() {
        return createTime;
    }

    public void setCreateTime(Date createTime) {
        this.createTime = createTime;
    }

    public Integer getStatus() {
        return status;
    }

    public void setStatus(Integer status) {
        this.status = status;
    }

    public Date getActivateTime() {
        return activateTime;
    }

    public void setActivateTime(Date activateTime) {
        this.activateTime = activateTime;
    }

    public Integer getUid() {
        return uid;
    }

    public void setUid(Integer uid) {
        this.uid = uid;
    }

    public Integer getCompanyId() {
        return companyId;
    }

    public void setCompanyId(Integer companyId) {
        this.companyId = companyId;
    }

    public Date getExpireTime() {
        return expireTime;
    }

    public void setExpireTime(Date expireTime) {
        this.expireTime = expireTime;
    }

    public Integer getPeriod() {
        return period;
    }

    public void setPeriod(Integer period) {
        this.period = period;
    }

    public Date getGuarantee() {
        return guarantee;
    }

    public void setGuarantee(Date guarantee) {
        this.guarantee = guarantee;
    }

    public Integer getBatch() {
        return batch;
    }

    public void setBatch(Integer batch) {
        this.batch = batch;
    }

    public String getExcelFileName() {
        return excelFileName;
    }

    public void setExcelFileName(String excelFileName) {
        this.excelFileName = excelFileName;
    }

    @Override
    public String toString() {
        return "ActivationCodeEntity{" +
                "activationcode='" + activationcode + '\'' +
                ", levelId='" + levelId + '\'' +
                ", createTime=" + createTime +
                ", status=" + status +
                ", activateTime=" + activateTime +
                ", uid=" + uid +
                ", companyId=" + companyId +
                ", expireTime=" + expireTime +
                ", period=" + period +
                ", excelFileName=" + excelFileName +
                '}';
    }
}
